<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

</body>

</html>
<script> 

    //1.
    // var arr = ["鹿晗", "王俊凯", "蔡徐坤", "彭于晏", "周杰伦", "刘德华", "赵本山"];
    // var newArr = [];
    // while (newArr.length < 4) {
    //     function getlist(min, max) {
    //         min = Math.ceil(min);
    //         max = Math.floor(max);
    //         return Math.floor(Math.random() * (max - min + 1)) + min;
    //     }
    //     var i = getlist(0, 6);
    //     if (newArr.indexOf(arr[i]) === -1) {
    //         newArr.push(arr[i]);
    //     }
    // }
    // console.log(newArr);

    //1.
    // var arr = ['鹿哈', '餐徐坤', '刘德华', '赵本本', '彭于晏', '周杰伦', '王俊凯']
    // var arr1 = []
    // while (arr1.length < 4) {
    //     var ss = Math.floor(Math.random() * 7)
    //     if (arr1.indexOf(arr[ss]) == -1) {
    //         arr1.push(arr[ss])
    //     }
    // }
    // console.log(arr1)

    // 2.
    // var arr = ['鹿哈', '餐徐坤', '刘德华', '赵本本', '彭于晏', '周杰伦', '王俊凯']
    // var newArr = {}
    // while(arr1.length<7){
    //     var ss = Math.floor(Math.random()*7)
    //     if(arr1.indexOf(arr[ss])==-1){
    //         arr1.push(arr[ss])
    //     }
    // }
    // console.log(arr1);


    // 1.
    var s = ['鹿晗','王俊凯','蔡徐坤','彭于晏','周杰伦','刘德华','赵本山']
    s.sort(function (){
        return Math.random() - 0.5
    })
    let a = s.slice(0, 4); 
    console.log(a); 

    // 2.
    var b = ['鹿晗','王俊凯','蔡徐坤','彭于晏','周杰伦','刘德华','赵本山']
    b.sort(function (){
        return Math.random() - 0.5
    })  
    console.log(b); 
</script>